home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / e33el2.zip / emacs / 19.33 / lisp / cal-tex.el (.txt) < prev    next >
LaTeX Document  |  1996-07-02  |  63KB  |  1,452 lines

  1. ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX.
  2. ;; Copyright (C) 1995 Free Software Foundation, Inc.
  3. ;; Author: Steve Fisk <fisk@bowdoin.edu>
  4. ;;      Edward M. Reingold <reingold@cs.uiuc.edu>
  5. ;; Keywords: calendar
  6. ;; Human-Keywords: Calendar, LaTeX
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 2, or (at your option)
  11. ;; any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  18. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. ;; Boston, MA 02111-1307, USA.
  20. ;;; Commentary:
  21. ;; This collection of functions implements the creation of LaTeX calendars
  22. ;; based on the user's holiday choices and diary file.
  23. ;; TO DO
  24. ;;     (*)  Add holidays and diary entries to daily calendar.
  25. ;;     (*)  Add diary entries to weekly calendar functions.
  26. ;;     (*)  Make calendar styles for A4 paper.
  27. ;;     (*)  Make daily and monthly styles Filofax paper.
  28. ;;     (*)  Improve the LaTeX command that produces the boxes in the monthly
  29. ;;          calendar to eliminate slight gap--what causes it?!
  30. ;;; Code:
  31. (require 'calendar)
  32. (autoload 'list-diary-entries "diary-lib" nil t)
  33. (autoload 'calendar-holiday-list "holidays" nil t)
  34. (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
  35. ;;; Customizable variables 
  36. (defvar cal-tex-which-days '(0 1 2 3 4 5 6)
  37.   "*The days of the week that are displayed on the portrait monthly calendar.
  38. Sunday is 0, Monday is 1, and so on.  The default is to print from Sunday to
  39. Saturday.  For example, use
  40.                     (setq cal-tex-which-days '(1 3 5))
  41. to only print Monday, Wednesday, Friday.")
  42. (defvar cal-tex-holidays t
  43.   "*If t (default), then the holidays are also printed.
  44. If finding the holidays is too slow, set this to nil.")
  45. (defvar cal-tex-diary nil
  46.   "*If t, the diary entries are printed in the calendar.")
  47. (defvar cal-tex-daily-string
  48.   '(let* ((year (extract-calendar-year date))
  49.           (day  (calendar-day-number date))
  50.           (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
  51.      (format "%d/%d" day  days-remaining))
  52.   "*An expression in the variable `date' whose value is placed on date.
  53. The string resulting from evaluating this expression is placed at the bottom
  54. center of `date' on the monthly calendar, next to the date in the weekly
  55. calendars, and in the top center of daily calendars.
  56. Default is ordinal day number of the year and the number of days remaining.
  57. As an example of what you do, setting this to
  58.     '(progn
  59.        (require 'cal-hebrew)
  60.        (calendar-hebrew-date-string date))
  61. will put the Hebrew date at the bottom of each day.")
  62. (defvar cal-tex-buffer "calendar.tex"
  63.   "*The name for the tex-ed calendar.")
  64. (defvar cal-tex-24 nil
  65.   "*If t, use a 24 hour clock in the daily calendar.")
  66. (defvar cal-tex-daily-start 8
  67.   "*The first hour of the daily calendar page.")
  68. (defvar cal-tex-daily-end 20
  69.   "*The last hour of the daily calendar page.")
  70. ;;; Definitions for LaTeX code
  71. (defvar  cal-tex-day-prefix "\\caldate{%s}{%s}"
  72.   "The initial LaTeX code for a day.  
  73. The holidays, diary entries, bottom string, and the text follow.")
  74. (defvar cal-tex-day-name-format "\\myday{%s}%%"
  75.   "The format for LaTeX code for a day name.  The names are taken from
  76. calendar-day-name-array.")
  77. (defvar cal-tex-cal-one-month
  78. "\\def\\calmonth#1#2%
  79. {\\begin{center}%
  80. \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
  81. \\end{center}}% 
  82. \\vspace*{-1.5cm}%
  83.   "LaTeX code for the month header")
  84. (defvar cal-tex-cal-multi-month
  85. "\\def\\calmonth#1#2#3#4%
  86. {\\begin{center}%
  87. \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
  88. \\end{center}}% 
  89. \\vspace*{-1.5cm}%
  90.   "LaTeX code for the month header")
  91. (defvar cal-tex-myday
  92. "\\renewcommand{\\myday}[1]%
  93. {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
  94.   "LaTeX code for a day heading")
  95. (defvar cal-tex-caldate
  96. "\\fboxsep=0pt
  97. \\long\\def\\caldate#1#2#3#4#5#6{%
  98.     \\fbox{\\hbox to\\cellwidth{%
  99.      \\vbox to\\cellheight{%
  100.        \\hbox to\\cellwidth{%
  101.           {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
  102.           \\raisebox{\\holidaymult\\cellheight}%
  103.                    {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
  104.        \\hbox to\\cellwidth{%
  105.            \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
  106.        \\hspace*{1mm}%
  107.        \\hbox to\\cellwidth{#6}%
  108.        \\vfill%
  109.        \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
  110.        \\vskip 1.4pt}%
  111.      \\hskip -0.4pt}}}
  112.   "LaTeX code to insert one box with date info in calendar.
  113. This definition is the heart of the calendar!")
  114. (defun cal-tex-list-holidays (d1 d2)
  115.   "Generate a list of all holidays from absolute date D1 to D2."
  116.   (let* ((result nil)
  117.          (start (calendar-gregorian-from-absolute d1))
  118.          (start-month (extract-calendar-month start))
  119.          (start-year (extract-calendar-year start)))
  120.     (increment-calendar-month start-month start-year 1)
  121.     (let* ((end (calendar-gregorian-from-absolute d2))
  122.            (end-month (extract-calendar-month end))
  123.            (end-year (extract-calendar-year end)))
  124.       (if (= (extract-calendar-day end) 1)
  125.           (increment-calendar-month end-month end-year -1))
  126.       (let* ((s (calendar-absolute-from-gregorian
  127.                  (list start-month 1 start-year)))
  128.              (e (calendar-absolute-from-gregorian
  129.                  (list end-month 1 end-year)))
  130.              (d s)
  131.              (never t)
  132.              (displayed-month start-month)
  133.              (displayed-year start-year))
  134.         (while (or never (<= d e))
  135.           (setq result (append result (calendar-holiday-list)))
  136.           (setq never nil)
  137.           (increment-calendar-month displayed-month displayed-year 3)
  138.           (setq d (calendar-absolute-from-gregorian
  139.                    (list displayed-month 1 displayed-year))))))
  140.     (let ((in-range)
  141.           (p result))
  142.       (while p
  143.         (and (car (car p))
  144.              (let ((a (calendar-absolute-from-gregorian (car (car p)))))
  145.                (and (<= d1 a) (<= a d2)))
  146.              (setq in-range (append (list (car p)) in-range)))
  147.         (setq p (cdr p)))
  148.       in-range)))
  149. (defun cal-tex-list-diary-entries (d1 d2)
  150.   "Generate a list of all diary-entries from absolute date D1 to D2."
  151.   (let ((diary-display-hook nil))
  152.     (list-diary-entries
  153.      (calendar-gregorian-from-absolute d1)
  154.      (1+ (- d2 d1)))))
  155. (defun cal-tex-preamble (&optional args)
  156.   "Insert the LaTeX preamble.
  157. Preamble Includes initial definitions for various LaTeX commands.
  158. Optional ARGS are included."
  159.   (set-buffer (get-buffer-create cal-tex-buffer))
  160.   (erase-buffer)
  161.   (insert "\\documentstyle")
  162.   (if args
  163.       (insert "[" args "]"))
  164.   (insert "{article}\n"
  165.           "\\hbadness 20000
  166. \\hfuzz=1000pt
  167. \\vbadness 20000
  168. \\marginparwidth 0pt
  169. \\oddsidemargin  -2cm
  170. \\evensidemargin -2cm
  171. \\marginparsep   0pt
  172. \\topmargin      0pt
  173. \\textwidth      7.5in
  174. \\textheight     9.5in
  175. \\newlength{\\cellwidth}
  176. \\newlength{\\cellheight}
  177. \\newlength{\\boxwidth}
  178. \\newlength{\\boxheight}
  179. \\newlength{\\cellsize}
  180. \\newcommand{\\myday}[1]{}
  181. \\newcommand{\\caldate}[6]{}
  182. \\newcommand{\\nocaldate}[6]{}
  183. \\newcommand{\\calsmall}[6]{}
  184. ;;;  Yearly calendars
  185. (defun cal-tex-cursor-year (&optional arg)
  186.   "Make a buffer with LaTeX commands for the year cursor is on.
  187. Optional prefix argument specifies number of years."
  188.   (interactive "P")
  189.   (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
  190.                 (if arg arg 1)))
  191. (defun cal-tex-cursor-year-landscape (&optional arg)
  192.   "Make a buffer with LaTeX commands for the year cursor is on.
  193. Optional prefix argument specifies number of years."
  194.   (interactive "P")
  195.   (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
  196.                 (if arg arg 1)
  197.                 t))
  198. (defun cal-tex-year (year n &optional l